﻿using FangPage.Common;
using FangPage.Core;
using FangPage.Data;
using FangPage.User;
using FangPage.User.Model;
using System;
using System.Collections.Generic;
using System.Text;

namespace FangPage.User.Controller
{
    public class user_list : UserController
    {
        public override void Controller()
        {
            string keyword = FPRequest.GetString("keyword");

            string departid = FPRequest.GetString("departid");

            if (ispost)
            {
                string ids = FPRequest.GetString("ids");

                DbHelper.ExcuteDelete<UserInfo>(ids);

                FPResponse.WriteSuccess("删除成功");
                return;
            }

            List<SqlParam> where = new List<SqlParam>();

            if (departid != "")
            {
                where.Add(DbHelper.MakeAndWhere("departid", departid));
            }

            if (keyword != "")
            {
                where.Add(DbHelper.MakeAndWhere('(',"username", WhereType.Like, keyword));
                where.Add(DbHelper.MakeOrWhere("realname", WhereType.Like, keyword));
                where.Add(DbHelper.MakeOrWhere(')', "mobile", WhereType.Like, keyword));
            }

            Pager pager = FPRequest.GetModel<Pager>();

            pager.total = DbHelper.ExcuteCount<UserInfo>(where.ToArray());

            List<UserInfo> data = DbHelper.ExcuteList<UserInfo>(pager.pagesize, pager.pageindex, where.ToArray());

            FPResponse.WriteData(data, pager);
        }
    }
}
